package com.turato.method;

import com.turato.method.model.DeliveryStateEnum;
import com.turato.method.model.bo.OrderBO;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @author tuhao
 * @date 2021/2/7 11:46 下午
 * @desc 移除参数列表
 */
public class RemoveFlagArgumentTwo {
    private Date deliveryDate(OrderBO anOrder, Boolean isRush) {
        // 是否加急
        if (isRush) {
            // 天
            int deliveryTimeDay = 0;
            if (DeliveryStateEnum.ORDERED.getState().equals(anOrder.getDeliveryState())) {
                deliveryTimeDay = 1;
            } else if (DeliveryStateEnum.PREPARED.getState().equals(anOrder.getDeliveryState())) {
                deliveryTimeDay = 2;
            }
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(anOrder.getPlacedOn());
            // 日期往后推N天
            calendar.add(Calendar.DATE, deliveryTimeDay + 1);
            return calendar.getTime();
        } else {
            // 天
            int deliveryTimeDay = 1;
            if (DeliveryStateEnum.ORDERED.getState().equals(anOrder.getDeliveryState())) {
                deliveryTimeDay = 2;
            } else if (DeliveryStateEnum.PREPARED.getState().equals(anOrder.getDeliveryState())) {
                deliveryTimeDay = 3;
            }
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(anOrder.getPlacedOn());
            // 日期往后推N天
            calendar.add(Calendar.DATE, deliveryTimeDay + 2);
            return calendar.getTime();
        }
    }

    /**
     * 加急
     * @param anOrder
     * @return
     */
    public Date rushDeliveryDate(OrderBO anOrder) {
        return deliveryDate(anOrder, true);
    }

    /**
     * 不加急，常规
     * @param anOrder
     * @return
     */
    public Date regularDeliveryDate(OrderBO anOrder) {
        return deliveryDate(anOrder, false);
    }
}
